<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算方案管理</title>
    <link href="../layui/css/layui.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="../image/kl_logo.png" rel="icon" type="image/png">
</head>
<body>
<div class="layui-form">
    <div class="layui-input-inline">
        <button class="layui-btn layui-btn-sm" lay-filter="formSearch"
                onclick="create_calculation_click()"><i class="layui-icon layui-icon-addition"></i>创建计算方案
        </button>
    </div>
</div>
<div id="content">

</div>
</body>

<script id="createDialog" type="text/html">
    <form class="layui-form" name="modify" action="" style="padding: 20px;padding-bottom: 5px;"
          lay-filter="editDialogForm">
        <div class="layui-form-item" style="margin-bottom:5px">
            <label class="layui-form-label" style="padding-left: 0px;padding-right: 5px;">名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-bottom:5px">
            <label class="layui-form-label" style="padding-left: 0px;padding-right: 5px;">内存(MB)</label>
            <div class="layui-input-inline">
                <input type="text" onkeyup="value=verify_number(this.value)" name="memory" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-bottom:5px">
            <label class="layui-form-label" style="padding-left: 0px;padding-right: 5px;">内核数</label>
            <div class="layui-input-inline">
                <input type="text" onkeyup="value=verify_number(this.value)"
                       name="cpu"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-bottom:0px">
            <label class="layui-form-label" style="padding-left: 0px;padding-right: 5px;">主频(MHZ)</label>
            <div class="layui-input-inline">
                <input type="text" onkeyup="value=verify_number(this.value)" value="0" name="speed" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </form>
</script>
<script src="../js/jquery.min.js"></script>
<script src="../js/config_util.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/util.js"></script>
<script src="../js/table_util.js"></script>
<script src="../js/data_handler.js"></script>
<script src="../js/data_util.js"></script>
<script src="../js/dialog_util.js"></script>
<script src="../js/render_util.js"></script>
<script>

    config_util.init(()=> {
        window.data_handler = new data_handler({
            uri: config_util.base_uri + "/management/calculation/scheme",
            idName: "id"
        });
        window.calculation_table_util = new table_util()
        calculation_table_util.render({
            elem: "#content",
            idName: "id",
            cols: [
                {width: 80, title: "ID", name: "id"},
                {width: 180, title: "名称", name: "name"},
                {width: 80, title: "内核数", name: "cpu"},
                {
                    width: 100, title: "主频", name: "speed", render: function (data) {
                        return data.speed > 0 ? data.speed : "主机默认"
                    }
                },
                {
                    width: 100, title: "内存", name: "memory", render: function (data) {
                        return render_util.get_memory_capacity(data.memory)
                    }
                },
                {
                    width: 180, title: "创建时间", render: function (data) {
                        return dateFormat("YYYY-mm-dd HH:MM:SS", new Date(data.createTime))
                    }
                }
            ],
            menu: [
                {
                    title: "销毁方案", icon: "layui-icon-delete", show: function (data) { return true }, click: destroy_calculation_click
                },
            ],
            handler: window.data_handler
        })
    })

    function create_calculation_click() {
        dialog_util.show_modify("#createDialog", "创建计算方案", "layui-icon-addition", "POST", config_util.base_uri+"/management/calculation/scheme/create", undefined, function (response) {
            if (response.code === 0) {
                calculation_table_util.append(response.data);
            } else {
                dialog_util.show_tool_tip('添加计算方案失败，错误码:' + response.code + '。错误信息:' + response.message);
            }
        })
    }

    function destroy_calculation_click(data) {
        dialog_util.show_confirm_dialog('确认删除计算方案', 'POST', config_util.base_uri+"/management/calculation/scheme/destroy", {id: data.id}, function (response) {
            if (response.code === 0) {
                calculation_table_util.remove(data);
            } else if (response.code) {
                dialog_util.show_tool_tip('销毁计算方案失败，错误码:' + response.code + '。错误信息:' + response.message);
            }
        })
    }




</script>